package cpb.module.evaluation.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.aries.ui.view.title.TitleBarView;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;

import cpb.module.evaluation.EvaluationPath;
import cpb.module.evaluation.R;
import cpb.module.evaluation.entity.Topic;
import tech.com.commoncore.base.BaseTitleActivity;
import tech.com.commoncore.entity.BaseTResp;
import tech.com.commoncore.utils.ToastUtil;

/**
 * Author:Cpb
 * Time  : 2019-08-06
 * Desc  : 开始页面
 */
@Route(path = EvaluationPath.START)
public class StartExamActivity extends BaseTitleActivity {

    private Button mBtnStart;

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("风险评测");
    }

    @Override
    public int getContentLayout() {
        return R.layout.evaluation_activity_start;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mBtnStart = findViewById(R.id.btn_start);

        mBtnStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadFirstTopic();
            }
        });
    }


    private void loadFirstTopic() {
        showLoading(getString(R.string.evaluation_tip_loading));
        ViseHttp.GET("yapi/risk/index")
                .addParam("page", "0")
                .request(new ACallback<BaseTResp<Topic>>() {
                    @Override
                    public void onSuccess(BaseTResp<Topic> data) {
                        hideLoading();
                        if (1 == data.code && data.data != null) {
                            ARouter.getInstance().build(EvaluationPath.EXAM).withSerializable("topic", data.data).withInt("pos",1).navigation();
                            finish();
                        } else {
                            ToastUtil.show(R.string.evaluation_tip_load_fail);
                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        hideLoading();
                        ToastUtil.show(R.string.evaluation_tip_load_fail);
                    }
                });
    }
}
